package com.juneng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.juneng.common.Condition;
import com.juneng.utils.BeanCopyUtils;
import com.juneng.entity.BookDiscount;
import com.juneng.mapper.BookDiscountMapper;
import com.juneng.service.IBookDiscountService;
import com.juneng.dto.BookDiscountDto;
import com.juneng.dto.BookDiscountQueryDto;
import com.juneng.vo.BookDiscountVo;
import org.springframework.stereotype.Service;
import lombok.AllArgsConstructor;
import java.util.List;
/**
 * 书籍折扣 服务实现类
 *
 * @author zds
 * @since 2021-07-30
 */
@Service
@AllArgsConstructor
public class BookDiscountServiceImpl implements IBookDiscountService {

    protected BookDiscountMapper bookDiscountMapper;
    @Override
    public IPage<BookDiscountVo> page(BookDiscountQueryDto dto) {
        IPage<BookDiscountVo> page = Condition.getPage(dto);
        return bookDiscountMapper.page(page,dto);
    }

    @Override
    public List<BookDiscount> list(BookDiscountQueryDto dto) {
        QueryWrapper<BookDiscount> queryWrapper = new QueryWrapper<>(BeanCopyUtils.copy(dto,BookDiscount.class));
        return bookDiscountMapper.selectList(queryWrapper);
    }

    @Override
    public Integer save(BookDiscountDto dto) {
        return bookDiscountMapper.insert(BeanCopyUtils.copy(dto,BookDiscount.class));
    }

    @Override
    public Integer updateById(BookDiscountDto dto) {
        return bookDiscountMapper.updateById(BeanCopyUtils.copy(dto,BookDiscount.class));
    }

    @Override
    public Integer deleteLogic(List<Integer> toIntList) {
        return bookDiscountMapper.deleteBatchIds(toIntList);
    }

    @Override
    public BookDiscount getById(Integer id) {
        return bookDiscountMapper.selectById(id);
    }
}
